package com.wzf.greattruth.zookeeper.queue.watcher;

import java.util.concurrent.CountDownLatch;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LatchChildWatcher implements Watcher {
    private static final Logger LOG = LoggerFactory.getLogger(LatchChildWatcher.class);

    CountDownLatch latch;

    public LatchChildWatcher() {
        latch = new CountDownLatch(1);
    }

    public void process(WatchedEvent event) {
        LOG.debug("Watcher fired on path: " + event.getPath() + " state: " + event.getState() + " type "
                + event.getType());
        latch.countDown();
    }

    public void await() throws InterruptedException {
        latch.await();
    }
}